package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.ProjectInfoDto;
import com.crm.jdy.common.dto.WConInfoDto;
import com.crm.jdy.common.pojo.ProjectInfo;
import com.crm.jdy.common.pojo.WConInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.WConInfoService;
import com.crm.jdy.service.project.ProjectInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 仓库列表API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "wConInfo", description ="仓库列表")
@RestController
@RequestMapping("/wConInfo")
public class WConInfoController{

    @Reference(version = "${service.version}", check = false)
    WConInfoService wConInfoService;

    @RateLimit()
    @ApiOperation("仓库列表信息")
    @PostMapping("/seleteWConInfo")
    public ResultVo seleteWConInfo(@RequestBody WConInfoDto projectInfoDto){
        PageInfo<WConInfo> list = wConInfoService.seleteWConInfo(projectInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新仓库列表信息")
    @PostMapping("/updateWConInfo")
    public ResultVo updateWConInfo(@ApiParam(value = "projectInfo", required = true)
                                      @Validated @RequestBody WConInfo projectInfo){
        boolean index = wConInfoService.updateWConInfo(projectInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加仓库列表信息")
    @PostMapping("/addProjectInfo")
    public ResultVo addWConInfo(@ApiParam(name = "projectInfo", required = false)
                                   @Validated @RequestBody WConInfo projectInfo){
        boolean list  = wConInfoService.addWConInfo(projectInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除仓库列表信息")
    @DeleteMapping("deleteWConInfo/{conId}")
    public ResultVo deleteWConInfo(@NotNull @ApiParam(name = "conId", value = "conId", required = true) @PathVariable String conId){
        boolean b = wConInfoService.removeWConInfo(conId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}